package com.beta.resource.utils.shell;

import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.exec.ProcessDestroyer;
import org.apache.commons.exec.PumpStreamHandler;

import com.beta.resource.utils.onStatusChange;

public class BaseShellStreamHandler extends PumpStreamHandler {
    private onStatusChange mListener = null;
    private Object data;
    private ProcessDestroyer mDestoryer;
    public BaseShellStreamHandler(onStatusChange listener, Object data){
        super();
        mListener = listener;
        this.data = data;
    }

    public void setProcessDestoryer(ProcessDestroyer destoryer){
        mDestoryer = destoryer;
    }

    protected Thread createPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
        BaseShellStreamPumper stream = new BaseShellStreamPumper(is, os, closeWhenExhausted, mListener, data);
        stream.setDestoryer(mDestoryer);
        final Thread result = new Thread(stream,
                "BaseShell Exec Stream Pumper");
        result.setDaemon(true);
        return result;
    }
}
